package com.working.libbase.binding

import android.graphics.Bitmap
import android.view.View
import android.widget.ImageView
import androidx.core.view.isGone
import androidx.databinding.BindingAdapter
import coil.load
import coil.transform.RoundedCornersTransformation
import dp

@BindingAdapter("bindingImage")
fun bindImage(imageView: ImageView, url: String?) {
    imageView.load(url) {
        transformations(RoundedCornersTransformation(4f.dp, 4f.dp, 4f.dp, 4f.dp))
        crossfade(true)
    }
}

@BindingAdapter("bindingImage")
fun bindImage(imageView: ImageView, url: Bitmap?) {
    imageView.load(url) {
        transformations(RoundedCornersTransformation(4f.dp, 4f.dp, 4f.dp, 4f.dp))
        crossfade(true)
    }
}

@BindingAdapter("bindingGone")
fun bindingGone(view: View, isGone: String?) {
    view.isGone = isGone.isNullOrBlank()
}

@BindingAdapter("bindingGone")
fun bindingGone(view: View, isGone: Boolean?) {
    view.isGone = true != isGone
}

@BindingAdapter("bindingGone")
fun bindingGone(view: View, isGone: List<*>?) {
    view.isGone = isGone.isNullOrEmpty()
}

